home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3bdevicemanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  7.1 KB  |  248 lines

  1. /*
  2.  *
  3.  * $Id: k3bdevicemanager.h 619556 2007-01-03 17:38:12Z trueg $
  4.  * Copyright (C) 2003-2007 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16.  
  17. #ifndef K3BDEVICEMANAGER_H
  18. #define K3BDEVICEMANAGER_H
  19.  
  20. #include <qobject.h>
  21. #include <qstring.h>
  22. #include <qstringlist.h>
  23. #include <qmemarray.h>
  24. #include <qptrlist.h>
  25.  
  26. #include "k3bdevice_export.h"
  27. #include <kdebug.h>
  28.  
  29. class KProcess;
  30. class KConfig;
  31. class K3bExternalBin;
  32.  
  33.  
  34. namespace K3bDevice {
  35.  
  36.   class Device;
  37.  
  38.   /**
  39.    * \brief Manages all devices.
  40.    *
  41.    * Searches the system for devices and maintains lists of them.
  42.    *
  43.    * <b>Basic usage:</b>
  44.    * \code
  45.    *   K3bDevice::DeviceManager* manager = new K3bDevice::DeviceManager( this );
  46.    *   manager->scanBus();
  47.    *   K3bDevice::Device* dev = manager->findDevice( "/dev/cdrom" );
  48.    * \endcode
  49.    */
  50.   class LIBK3BDEVICE_EXPORT DeviceManager : public QObject
  51.     {
  52.       Q_OBJECT
  53.  
  54.     public:
  55.       /**
  56.        * Creates a new DeviceManager
  57.        */
  58.       DeviceManager( QObject* parent = 0, const char* name = 0 );
  59.       virtual ~DeviceManager();
  60.  
  61.       /**
  62.        * By default the DeviceManager makes the Devices check their writing modes.
  63.        * This includes commands to be sent which require writing permissions on the
  64.        * devices and might take some time.
  65.        *
  66.        * So if you don't need the information about the writing modes use this method
  67.        * to speed up the device detection procedure.
  68.        *
  69.        * Be aware that this only refers to CD writing modes. If you only want to handle
  70.        * DVD devices it's always save to set this to false.
  71.        */
  72.       void setCheckWritingModes( bool b );
  73.  
  74.       /**
  75.        * \deprecated use findDevice( const QString& )
  76.        */
  77.       Device* deviceByName( const QString& );
  78.  
  79.       /**
  80.        * Search an SCSI device by SCSI bus, id, and lun.
  81.        *
  82.        * \note This method does not initialize new devices.
  83.        *       Devices cannot be found until they have been added via addDevice(const QString&)
  84.        *       or scanBus().
  85.        *
  86.        * \return The corresponding device or 0 if there is no such device.
  87.        */
  88.       Device* findDevice( int bus, int id, int lun );
  89.  
  90.       /**
  91.        * Search a device by blockdevice name.
  92.        *
  93.        * \note This method does not initialize new devices.
  94.        *       Devices cannot be found until they have been added via addDevice(const QString&)
  95.        *       or scanBus().
  96.        *
  97.        * \return The corresponding device or 0 if there is no such device.
  98.        */
  99.       Device* findDevice( const QString& devicename );
  100.  
  101.       /**
  102.        * Before getting the devices do a @ref scanBus().
  103.        * \return List of all cd writer devices.
  104.        * \deprecated use cdWriter()
  105.        */
  106.       const QPtrList<Device>& burningDevices() const;
  107.  
  108.       /**
  109.        * \return List of all reader devices without writer devices.
  110.        * \deprecated use cdReader()
  111.        **/
  112.       const QPtrList<Device>& readingDevices() const;
  113.  
  114.       /**
  115.        * Before getting the devices do a @ref scanBus() or add 
  116.        * devices via addDevice( const QString& ).
  117.        *
  118.        * \return List of all devices.
  119.        */
  120.       const QPtrList<Device>& allDevices() const;
  121.  
  122.       /**
  123.        * Before getting the devices do a @ref scanBus() or add 
  124.        * devices via addDevice( const QString& ).
  125.        *
  126.        * \return List of all cd writer devices.
  127.        */
  128.       const QPtrList<Device>& cdWriter() const;
  129.  
  130.       /**
  131.        * Before getting the devices do a @ref scanBus() or add 
  132.        * devices via addDevice( const QString& ).
  133.        *
  134.        * \return List of all cd reader devices.
  135.        */
  136.       const QPtrList<Device>& cdReader() const;
  137.  
  138.       /**
  139.        * Before getting the devices do a @ref scanBus() or add 
  140.        * devices via addDevice( const QString& ).
  141.        *
  142.        * \return List of all DVD writer devices.
  143.        */
  144.       const QPtrList<Device>& dvdWriter() const;
  145.  
  146.       /**
  147.        * Before getting the devices do a @ref scanBus() or add 
  148.        * devices via addDevice( const QString& ).
  149.        *
  150.        * \return List of all DVD reader devices.
  151.        */
  152.       const QPtrList<Device>& dvdReader() const;
  153.  
  154.       /**
  155.        * Before getting the devices do a @ref scanBus() or add 
  156.        * devices via addDevice( const QString& ).
  157.        *
  158.        * \return List of all Blue Ray reader devices.
  159.        */
  160.       const QPtrList<Device>& blueRayReader() const;
  161.  
  162.       /**
  163.        * Before getting the devices do a @ref scanBus() or add 
  164.        * devices via addDevice( const QString& ).
  165.        *
  166.        * \return List of all Blue Ray writer devices.
  167.        */
  168.       const QPtrList<Device>& blueRayWriters() const;
  169.  
  170.       /**
  171.        * Reads the device information from the config file.
  172.        */
  173.       virtual bool readConfig( KConfig* );
  174.  
  175.       virtual bool saveConfig( KConfig* );
  176.  
  177.  
  178.     public slots:
  179.       /**
  180.        * Writes a list of all devices to stderr.
  181.        */
  182.       void printDevices();
  183.  
  184.       /**
  185.        * Scan the system for devices. Call this to initialize all devices.
  186.        * 
  187.        * If the system uses the HAL device deamon it is possible to use
  188.        * HalConnection instead of calling this method.
  189.        *
  190.        * \return Number of found devices.
  191.        **/
  192.       virtual int scanBus();
  193.  
  194.       /**
  195.        * Clears the writers and readers list of devices.
  196.        */
  197.       virtual void clear();
  198.  
  199.       /**
  200.        * Add a new device.
  201.        *
  202.        * \param dev Name of a block device or link to a block device. If the 
  203.        *            corresponding device has already been detected it will simply
  204.        *            be returned. Otherwise if a device is found it will be initialized
  205.        *            and added to the internal lists (meaning it can be accessed through
  206.        *            emthods like cdReader()).
  207.        *
  208.        * Called by scanBus()
  209.        *
  210.        * \return The device if it could be found or 0 otherwise.
  211.        */
  212.       virtual Device* addDevice( const QString& dev );
  213.  
  214.       /**
  215.        * Remove a device from the device manager. Basicly this method
  216.        * only makes sense in combination with the HalConnection. Connect
  217.        * it to the deviceRemoved signal.
  218.        */
  219.       virtual void removeDevice( const QString& dev );
  220.  
  221.     signals:
  222.       /**
  223.        * Emitted if the device configuration changed, i.e. a device was added or removed.
  224.        */
  225.       void changed( K3bDevice::DeviceManager* );
  226.       void changed();
  227.  
  228.     private:
  229.       bool testForCdrom( const QString& );
  230.       bool determineBusIdLun( const QString &dev, int& bus, int& id, int& lun );
  231.       QString resolveSymLink( const QString& path );
  232.  
  233.       class Private;
  234.       Private* d;
  235.  
  236.       /**
  237.        * Add a device to the managers device lists and initialize the device.
  238.        */
  239.       Device *addDevice( Device* );
  240.  
  241.       void BSDDeviceScan();
  242.       void NetBSDDeviceScan();
  243.       void LinuxDeviceScan();
  244.     };
  245. }
  246.  
  247. #endif
  248.